﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace MadProps.Controls
{
    public abstract class SelfTemplatingBase : ContentControl
    {
        public SelfTemplatingBase()
        {
            IsTabStop = false;
            VerticalAlignment = System.Windows.VerticalAlignment.Center;

            DataContextChanged += SelfTemplatingBase_DataContextChanged;
        }

        void SelfTemplatingBase_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var selfTemplating = this.DataContext as Templating.ISelfTemplatingDataContext;
            if (selfTemplating != null)
            {
                var template = selfTemplating.SelectTemplate(this);
                if (template != null)
                {
                    this.ContentTemplate = template;
                }
            }
        }
    }
}
